<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>File Upload</title>
</head>
<body>
<form id="uploadForm">
    <input type="file" id="fileInput" name="file" />
    <button type="button" onclick="uploadFile()">上传</button>
</form>

<script>
  // 原始的文件上传逻辑
  function uploadFile() {
    const fileInput = document.querySelector('#fileInput');
    const file = fileInput.files[0];
    const allowedTypes = ['image/jpeg', 'image/png'];

    if (file && allowedTypes.includes(file.type)) {
      const formData = new FormData();
      formData.append('file', file);

      console.log('文件校验通过');
    } else {
      console.error('文件类型不正确');
    }
  }
</script>
</body>
</html>
